package com.young.msg.service.impl;

import com.young.interfaces.log.annotation.Log;
import com.young.interfaces.msg.service.IMsgMailOutService;
import com.young.msg.core.MailSenderControlCenter;
import com.young.msg.model.MailSendCommand;
import org.springframework.stereotype.Service;

/**
 * 邮件服务
 *
 * @author wangjy
 * @date 2021/10/30 11:22:50
 */
@Service
public class MsgMailOutServiceImpl implements IMsgMailOutService {

    /**
     * 发送邮件
     *
     * @param receiver 收件人邮箱
     * @param title    标题
     * @param content  内容
     */
    @Log("发送邮件")
    @Override
    public void sendMail(String receiver, String title, String content) {
        this.sendMailBySender(null, receiver, title, content);
    }

    /**
     * 发送邮件by指定邮箱
     *
     * @param senderCode 发件邮箱标识, 可以在平台配置
     * @param receiver   收件人邮箱
     * @param title      标题
     * @param content    内容
     */
    @Log("发送邮件by指定邮箱")
    @Override
    public void sendMailBySender(String senderCode, String receiver, String title, String content) {
        // 构造邮件发送命令对象
        MailSendCommand command = MailSendCommand.build(senderCode, receiver, title, content);
        // 发送邮件
        MailSenderControlCenter.send(command);
    }
}
